<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> Superc hecker </title>
<link rel="stylesheet" type="text/css" href="scripts/katstyle.css">
</head>



<?php

// Anfang Konfiguration:Bitte Daten eintragen

include "../../conf.php";
// get all menuitems with 1 query
$result = mysql_query("
    SELECT
        id, parentId, name
    FROM
        notizmenu
    ORDER BY
        reihe, parentId, name
");
?>

<?php
// prepare special array with parent-child relations
$menuData = array(
    'items' => array(),
    'parents' => array()
);

while ($menuItem = mysql_fetch_assoc($result))
{
    $menuData['items'][$menuItem['id']] = $menuItem;
    $menuData['parents'][$menuItem['parentId']][] = $menuItem['id'];
}
?>

<?php
// menu builder function, parentId 0 is the root
function buildMenu1($parentId, $menuData)
{
    $html = '';

    if (isset($menuData['parents'][$parentId]))
    {
        $html = '<ul id="example4">';
        foreach ($menuData['parents'][$parentId] as $itemId)
        {
            $html .= '<li><a href="adressen_index.php?katname='. $menuData['items'][$itemId]['name'].'">' . $menuData['items'][$itemId]['name'];

            // find childitems recursively
            $html .= buildMenu1($itemId, $menuData);

            $html .= '</a></li>';
        }
        $html .= '</ul>';
    }

    return $html;
}

// output the menu
echo buildMenu1(0, $menuData);
?>